//
//  UIView+Frame.m
//  MDSnSpeedNews
//
//  Created by Medalands on 16/7/29.
//  Copyright © 2016年 Medalands. All rights reserved.
//

#import "UIView+FPFrame.h"

@implementation UIView (FPFrame)

// 调用X的setter方法，我们传进来一个值，方法吧这个值赋给控件的frame.origin.x
- (void)setFp_x:(CGFloat)fp_x{
    // self 就等于调用这个方法的view
    CGRect frame = self.frame;
    
    frame.origin.x = fp_x;
    
    self.frame = frame;
}

// 调用x的getter方法，我们把控件的frame.origin.x传出去
- (CGFloat)fp_x{
    
    return self.frame.origin.x;
}

- (void)setFp_y:(CGFloat)fp_y{
    // self 就等于调用这个方法的view
    CGRect frame = self.frame;
    
    frame.origin.y = fp_y;
    
    self.frame = frame;
}

- (CGFloat)fp_y{
    
    return self.frame.origin.y;
}

- (void)setFp_width:(CGFloat)fp_width{
    // self 就等于调用这个方法的view
    CGRect frame = self.frame;
    
    frame.size.width = fp_width;
    
    self.frame = frame;
}

- (CGFloat)fp_width{
    
    return self.frame.size.width;
}

- (void)setFp_height:(CGFloat)fp_height{
    // self 就等于调用这个方法的view
    CGRect frame = self.frame;
    
    frame.size.height = fp_height;
    
    self.frame = frame;
}

- (CGFloat)fp_height{
    
    return self.frame.size.height;
}

- (void)setFp_centerX:(CGFloat)fp_centerX{
    
    // self 就等于调用这个方法的view
    CGPoint center = self.center;
    
    center.x = fp_centerX;
    
    self.center = center;
}

- (CGFloat)fp_centerX{
    return self.center.x;
}

- (void)setFp_centerY:(CGFloat)fp_centerY{
    
    // self 就等于调用这个方法的view
    CGPoint center = self.center;
    
    center.y = fp_centerY;
    
    self.center = center;
    
}

- (CGFloat)fp_centerY{
    return self.center.y;
}


- (void)setFp_bottom:(CGFloat)fp_bottom{
    
    CGRect frame = self.frame;
    
    frame.origin.y = fp_bottom - frame.size.height;
    
    self.frame = frame;
    
    
}

- (CGFloat)fp_bottom{
    return CGRectGetMaxY(self.frame);
}

- (void)setFp_left:(CGFloat)fp_left{
    [self setFp_x:fp_left];
}

- (CGFloat)fp_left{
    return self.frame.origin.x;
    
}

- (void)setFp_right:(CGFloat)fp_right{
    CGRect frame = self.frame;
    
    frame.origin.x = fp_right - frame.size.width;
    
    self.frame = frame;
}


- (CGFloat)fp_right{
    return self.frame.origin.x + self.frame.size.width ;
}

- (void)setFp_size:(CGSize)fp_size{
    CGRect frame = self.frame;
    
    frame.size = fp_size;
    
    self.frame = frame;
}

- (CGSize)fp_size{
    return self.frame.size;
}


- (void)fp_addCornerRadius:(CGFloat)radius
{
    [self.layer setMasksToBounds:YES];
    
    [self.layer setCornerRadius:radius];
    
}

- (void) fp_addBottomShadow{
    [self.layer setShadowColor:[UIColor blackColor].CGColor];
    [self.layer setShadowOffset:CGSizeMake(0, 0)];
    [self.layer setShadowOpacity:0.1];
}

- (void)fp_changeWidthWithTitle:(NSString *)title font:(CGFloat)font space:(CGFloat)space{
    
    CGSize titleSize = [title sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:font]}];
    
    self.fp_width = titleSize.width+space;
}


@end
